/*
 * Class Human.java
 * 9.06.2012
 * :)
 * Class represents human model, which consists of 
 * different organs and life characteristics.
 * Each life characteristics depends on multiple organ parameter,
 * which could be changed according live activity
 */

package humanMirror.model.human;

import java.util.ArrayList;

/**
 * Class implements human like a list of organs and their characteristics
 * Depends on them changes live parameters which may cause death. By default
 * human initialized like a newborn with neutral parameters (parameters varies
 * from 0(worst) to +100(best).Neutral is 0;
 *
 * @author Vasyl Khyzhniak
 * @author Anton Samarsky
 * @version 2.0 26 jul 2012
 */
public class Human {
    private int totalLife;

    private ArrayList<Organ> organs;

    /**
     * Human Class Constructor Creates a "human" with newborn human parameter
     * (they are equals to 0)
     */
    public Human() {
        //TODO: add organ parameters
        totalLife = 100;
        Organ brain = setOneOrganInfo(SomeConstants.Organs.BRAIN.getOrganNumber(), 50, 60, 70, 80);
        //Organ brain = setOneOrganInfo(SomeConstants.BRAIN, 50, 60, 70, 80);
        Organ liver = setOneOrganInfo(SomeConstants.Organs.LIVER.getOrganNumber(), 60, 70, 80, 90);
        setOrgans(brain, liver);
//      //organs.add(brain.getID(), brain);

        //  OneOrganInfo liverParameters = new OneOrganInfo();
//        liverParameters.setParameters(60, 70, 80, 90);
//        Organ liver = new Organ(SomeConstants.Organs.LIVER.getOrganNumber(), liverParameters);
        //organs.add(SomeConstants.Organs.LIVER.getOrganNumber(), liver);
        //organs.add(liver.getID(), liver);setOrgans();
    }

    public Human(Organ... organArray) {
        this.totalLife = 100;
        setOrgans(organArray);
    }

    private void setOrgans(Organ... organsArray) {
        organs = new ArrayList<Organ>();
        for (Organ organ : organsArray) {
            organs.add(organ.getID(), organ);
        }
    }

    public Organ setOneOrganInfo(byte organIndex, int... parameterValues) {
        OneOrganInfo oneOrganInfo = new OneOrganInfo();
        oneOrganInfo.setParameters(parameterValues);
        return new Organ(organIndex, oneOrganInfo);
    }

    public int getTotalLife() {
        return totalLife;
    }

    public OneOrganInfo getOrganParameters(int name) {
        return organs.get(name).getAllParameters();
    }

    public void setOrgansParameters(OrganInfo sumArray) {
        for (Organ organ : organs) {
            organ.accumulateAllParameterChanges(sumArray.getOneOrganParameters(organ.getID()));
        }
    }
}
